from ..builder import Builder


class CBuilder(Builder):
    PARAMS_PREFIX = "c_"
    
    @classmethod
    def scan(cls, node):
        f = open(node.filename, "r")
        for line in f:
            line = line.strip()
            if line.startswith("#include"):
                line = line[8:].strip()
                fn = line[1:-1]
                if line[0] == "<":
                    node.new_child(fn, searchpath = node.params.c_include_path)
                else:
                    node.new_child(fn)
        f.close()
    
    @classmethod
    def get_output(cls, node):
        return node.basename + ".o"
    
    @classmethod
    def build(cls, node):
        proc = node.params.c_compiler(node.filename, node.output, node.params)
        return BuildResult(proc)


def register_builder():
    CBuilder.register("c")
    CppBuilder.register("cc", "cpp", "c++")
    HBuilder.register("h")






















